package com.cfpl.admin_vegetable_service.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cfpl.admin_vegetable_service.DTO.VegNameAndPlantLocationDTO;
import com.cfpl.admin_vegetable_service.VO.QualityInspectionPageVO;
import com.cfpl.admin_vegetable_service.service.QualityInspectionRecordService;
import com.cfpl.project_common.pojo.QualityInspectionRecord;
import com.cfpl.project_common.result.BaseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Auther: wrp
 * @Date: 2023/11/2 - 11:04
 * @Description: com.cfpl.admin_vegetable_service.controller
 * @version: 1.0
 */
@RestController
@Slf4j
@Api(tags = "质量检测记录相关接口")
@RequestMapping("/qualityInspectionRecord")
public class QualityInspectionRecordController {

    @Autowired
    private QualityInspectionRecordService qualityInspectionRecordService;

    /**
     *  功能描述：分页查询质量检测记录表
     * @param currentPage  当前页
     * @param pageSize  页面条数
     * @param condition 查询条件
     * @return  质量检测记录
     */
    @ApiOperation("分页查询质量检测记录")
    @GetMapping("/pageQueryQualityInspectionRecord")
    public BaseResult<Page<QualityInspectionPageVO>> pageQuery(int currentPage, int pageSize, String condition) {
        IPage<QualityInspectionPageVO> page = new Page<>(currentPage,pageSize);
        Page<QualityInspectionPageVO> resultPage = qualityInspectionRecordService.queryPage(page, condition);
        return BaseResult.ok(resultPage);
    }

    /**
     * 功能描述：添加质量检测记录
     * @param qualityInspectionRecord 质量检测记录对象
     * @return
     */
    @ApiOperation("添加质量检测记录")
    @PostMapping("/addQualityInspectionRecord")
    public BaseResult addQualityInspectionRecord(@RequestBody QualityInspectionRecord qualityInspectionRecord) {
        qualityInspectionRecordService.addQualityInspectionRecord(qualityInspectionRecord);
        return BaseResult.ok();
    }

    /**
     * 功能描述：根据样品编号（进场批次）查询果蔬名称和种植地
     * @param sampleNumber
     * @return
     */
    @ApiOperation("根据样品编号（进场批次）查询果蔬名称和种植地")
    @GetMapping("/queryVegNameAndPlantLocationBySampleNumber")
    public BaseResult<VegNameAndPlantLocationDTO> queryBySampleNumber(@RequestParam("sampleNumber") String sampleNumber) {
        VegNameAndPlantLocationDTO dto = qualityInspectionRecordService.queryBySampleNumber(sampleNumber);
        return BaseResult.ok(dto);
    }

    /**
     * 功能描述：根据质量检测id查询单条记录
     * @param id  质量检测id
     * @return 质量检测单条记录
     */
    @ApiOperation("根据质量检测id查询单条记录")
    @GetMapping("/queryQualityInspectionRecordById/{id}")
    public BaseResult<QualityInspectionRecord> queryById(@PathVariable("id") Long id) {
        QualityInspectionRecord qualityInspectionRecord = qualityInspectionRecordService.queryQualityInspectionRecordById(id);
        return BaseResult.ok(qualityInspectionRecord);
    }

}
